/***************************************************************
 * Name:      QtHelper
 * Purpose:   Code::Blocks plugin
 * Author:    Sviridov Michael Alexandrovich (2mihail@mail.ru)
 * Created:   2008-09-20
 * Copyright: Sviridov Michael Alexandrovich
 * License:   GPL
 **************************************************************/
#ifndef QT_PRJ_DLG_INCLUDED
#define QT_PRJ_DLG_INCLUDED

#include "configurationpanel.h"
#include <vector>
//-------------------------------------------------
class cbProject;
//-------------------------------------------------
/// Struct of settings that can be changed in this dialog
struct ConfigData
{
	// this block only for targets (not entire project)
	bool 			modified;

	int 			output_type;
	wxString 		output_filename;
	wxString 		exe_work_dir;
	wxString 		objects_dir;
	// end of block

	wxArrayString 	compiler_opts;
	wxArrayString 	linker_opts;

	wxArrayString 	inc_dirs;
	wxArrayString 	lib_dirs;

	wxArrayString 	libs;

	wxString 		custom_tags;
};
//-----------------------------------------------------------
/// Namely Qt project configuration dialog
class QtPrjDlg : public cbConfigurationPanel
{
public:
    QtPrjDlg(wxWindow* parent, cbProject* project);
    ~QtPrjDlg();

    virtual wxString GetTitle() const
    {
		return _T("Qt Helper");
	}

    virtual wxString GetBitmapBaseName() const
	{
		return _T("generic-plugin");
	}

    virtual void OnApply() {save();}
    virtual void OnCancel() {}

private:
    bool 					loading;
    bool					modified;		///< checkbox state was switched
    bool 					loaded;			///< data was already loaded (when user enables usage of QtHelper)
    ConfigData				project_cfg;
    std::vector<ConfigData> targets_cfg;

    cbProject* project;

    void load();
    void save();
    void save_project_data();
    void save_target_data(const wxTreeItemId &id);
    void load_project_data();
    void load_target_data(const wxTreeItemId &id);
    ConfigData& get_config(const wxTreeItemId &id = wxTreeItemId());
    wxString browse_dir(const wxString &text, const wxString &dir);

	// pointer getters for form widgets
	wxCheckBox* use_qt_check();

	wxTreeCtrl* targets_tree();
	wxNotebook* qt_prj_settings();
	wxPanel* build_options();
	wxPanel* build_flags();
	wxPanel* search_paths();
	wxPanel* link_libs();

	wxListBox* inc_dir_lst();
	wxButton* add_inc_dir_btn();
	wxButton* edit_inc_dir_btn();
	wxButton* delete_inc_dir_btn();
	wxButton* clear_inc_dirs_btn();
	wxSpinButton* move_inc_dir_btn();

	wxListBox* lib_dir_lst();
	wxButton* add_lib_dir_btn();
	wxButton* edit_lib_dir_btn();
	wxButton* delete_lib_dir_btn();
	wxButton* clear_lib_dirs_btn();
	wxSpinButton* move_lib_dir_btn();

	wxListBox* libs_lst();
	wxButton* add_lib_btn();
	wxButton* edit_lib_btn();
	wxButton* delete_lib_btn();
	wxButton* clear_libs_btn();
	wxSpinButton* move_lib_btn();

	wxChoice* output_type_edit();
	wxTextCtrl* output_filename_edit();
	wxTextCtrl* exe_work_dir_edit();
	wxTextCtrl* obj_dir_edit();

	wxListBox* compiler_opts_lst();
	wxButton* add_compiler_opt_btn();
	wxButton* delete_compiler_opt_btn();
	wxButton* clear_compiler_opts_btn();

	wxListBox* linker_opts_lst();
	wxButton* add_linker_opt_btn();
	wxButton* delete_linker_opt_btn();
	wxButton* clear_linker_opts_btn();

	wxTextCtrl* custom_tags_edit();

	// work with list of dirs
	void add_dir(wxListBox *lst);
	void edit_dir(wxListBox *lst);
	void delete_list_item(wxListBox *lst);
	void clear_list(wxListBox *lst);
	void move_up_list_item(wxListBox *lst);
	void move_down_list_item(wxListBox *lst);

	// update functions
	void update_compiler_opt_btns();
	void update_linker_opt_btns();
	void update_include_dir_btns();
	void update_lib_dir_btns();
	void update_lib_btns();
	void update_prj_settings();

	// handlers
	void on_use_qt(wxCommandEvent&);

	void on_target_changing(wxTreeEvent&);
	void on_target_changed(wxTreeEvent&);
	void on_page_changed(wxNotebookEvent&);

	void on_select_output_type(wxCommandEvent&);
    void on_browse_output_filename_click(wxCommandEvent&);
    void on_output_filename_changed(wxCommandEvent&);
    void on_browse_exe_work_dir_click(wxCommandEvent&);
    void on_exe_work_dir_changed(wxCommandEvent&);
    void on_browse_objects_dir_click(wxCommandEvent&);
    void on_objects_dir_changed(wxCommandEvent&);

    void on_select_compiler_opt(wxCommandEvent&);
    void on_add_compiler_opt_click(wxCommandEvent&);
    void on_delete_compiler_opt_click(wxCommandEvent&);
    void on_clear_compiler_opts_click(wxCommandEvent&);

	void on_select_linker_opt(wxCommandEvent&);
    void on_add_linker_opt_click(wxCommandEvent&);
    void on_delete_linker_opt_click(wxCommandEvent&);
    void on_clear_linker_opts_click(wxCommandEvent&);

    void on_select_include_path(wxCommandEvent&);
    void on_add_include_path_click(wxCommandEvent&);
    void on_edit_include_path_click(wxCommandEvent&);
    void on_delete_include_path_click(wxCommandEvent&);
    void on_clear_include_paths_click(wxCommandEvent&);
	void on_move_up_include_path(wxSpinEvent&);
    void on_move_down_include_path(wxSpinEvent&);

    void on_select_lib_path(wxCommandEvent&);
    void on_add_lib_path_click(wxCommandEvent&);
    void on_edit_lib_path_click(wxCommandEvent&);
    void on_delete_lib_path_click(wxCommandEvent&);
    void on_clear_lib_path_click(wxCommandEvent&);
    void on_move_up_lib_path(wxSpinEvent&);
    void on_move_down_lib_path(wxSpinEvent&);

    void on_select_lib(wxCommandEvent&);
    void on_add_lib_click(wxCommandEvent&);
    void on_edit_lib_click(wxCommandEvent&);
    void on_delete_lib_click(wxCommandEvent&);
    void on_clear_lib_click(wxCommandEvent&);
    void on_move_up_lib(wxSpinEvent&);
    void on_move_down_lib(wxSpinEvent&);

    void on_custom_tags_changed(wxCommandEvent&);

    TiXmlElement* getXmlElement(TiXmlNode *parent, const char *name) const;

    DECLARE_EVENT_TABLE()
};
//-----------------------------------------------------------
#endif
